﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class DALBooking : IDALBooking, IDisposable
    {
        private CarBatteryEntities context;
        private bool disposed = false;

        public DALBooking(CarBatteryEntities context)
        {
            this.context = context;
        }

        public IEnumerable<Booking> GetBookings()
        {
            return context.Booking.AsEnumerable();
        }

        public Booking GetBookingByID(int bookingID)
        {
            return context.Booking.Find(bookingID);
        }

        public void InsertBooking(Booking booking)
        {
            context.Booking.Add(booking);
        }

        public void DeleteBooking(int bookingID)
        {
            context.Booking.Remove(GetBookingByID(bookingID));
        }

        public void UpdateBooking(Booking booking)
        {
            context.Entry(booking).State = EntityState.Modified;
        }

        public int Save()
        {
            return context.SaveChanges();
        }

        public virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                    context.Dispose();

                this.disposed = true;
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}